SHELL = /bin/bash

# Auto-detect Docker Compose command
DOCKER_COMPOSE := $(shell docker compose version 2>/dev/null)

ifeq ($(DOCKER_COMPOSE),)
	# Old version: docker-compose (with hyphen)
	DOCKER_COMPOSE = docker-compose
else
	# New version: docker compose (space)
	DOCKER_COMPOSE = docker compose
endif

.PHONY: build up down restart logs shell artisan

build:
	$(DOCKER_COMPOSE) -f docker-compose.yml build --pull

up:
	$(DOCKER_COMPOSE) -f docker-compose.yml up -d

down:
	$(DOCKER_COMPOSE) -f docker-compose.yml down

restart:
	$(DOCKER_COMPOSE) -f docker-compose.yml up -d --force-recreate

logs:
	$(DOCKER_COMPOSE) -f docker-compose.yml logs -f

shell:
	$(DOCKER_COMPOSE) -f docker-compose.yml exec app sh

artisan:
	$(DOCKER_COMPOSE) -f docker-compose.yml exec app artisan $(filter-out $@,$(MAKECMDGOALS))
%:
	@:
